SmoothL1Loss
计算平滑L1损失函数
\[\begin{split}\text{loss}(x_1, x_2) = \begin{cases}
\frac{(x_1 - x_2)^2}{2\beta}, & \text{if } |x_1 - x_2| < \beta \\
|x_1 - x_2| - \frac{\beta}{2}, & \text{otherwise}
\end{cases}\end{split}\]
其中 \(x_1\) 为预测值,\(x_2\) 为目标值,\(\beta\) 为平滑参数。
- 输入:
predict - 预测值数据地址。
target - 目标值数据地址。
length - 计算长度。
beta - 平滑参数(FT78NE平台为float值,MT7004平台为half*指针)。
core_mask(int, 可选) - 核掩码(仅适用于共享存储版本)。
- 输出:
out - 计算结果地址。
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持int8, fp32
MT7004 支持fp16, fp32
共享存储版本:
-
void i8_smoothl1loss_s(int8_t *out, int8_t *predict, int8_t *target, int length, float beta, int core_mask)
-
void fp_smoothl1loss_s(float *out, float *predict, float *target, int length, float beta, int core_mask)
-
void hp_smoothl1loss_s(half *out, half *predict, half *target, int length, half *beta, int core_mask)
C调用示例:
1//FT78NE示例 2#include <stdio.h> 3#include <smoothl1loss.h> 4 5int main(int argc, char* argv[]) { 6 float *predict = (float *)0xA0000000; //predict在DDR空间 7 float *target = (float *)0xB0000000; //target在DDR空间 8 float *out = (float *)0xC0000000; //out在DDR空间 9 int length = 1000; 10 float beta = 1.0f; 11 int core_mask = 0xff; 12 fp_smoothl1loss_s(out, predict, target, length, beta, core_mask); 13 return 0; 14}
私有存储版本:
-
void i8_smoothl1loss_p(int8_t *out, int8_t *predict, int8_t *target, int length, float beta)
-
void fp_smoothl1loss_p(float *out, float *predict, float *target, int length, float beta)
-
void hp_smoothl1loss_p(half *out, half *predict, half *target, int length, half *beta)
C调用示例:
1//FT78NE示例 2#include <stdio.h> 3#include <smoothl1loss.h> 4 5int main(int argc, char* argv[]) { 6 float *predict = (float *)0x10810000; //predict在L2空间 7 float *target = (float *)0x10850000; //target在L2空间 8 float *out = (float *)0x108A0000; //out在L2空间 9 int length = 1000; 10 float beta = 1.0f; 11 fp_smoothl1loss_p(out, predict, target, length, beta); 12 return 0; 13}